﻿using System;
using System.Collections.Generic;

namespace MyLib.Data {
	/// <summary>
	/// ChangePasswordTable
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class ChangePasswordTable : System.Data.DataTable, System.Collections.Generic.IList<ChangePasswordRow> {
		/// <summary>
		/// 
		/// </summary>
		public const int ColumnUserId = 0;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnPassword = 1;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnNewPassword = 2;

		/// <summary>
		/// Create a new instance of ChangePasswordTable.
		/// </summary>
		protected override System.Data.DataTable CreateInstance() {
			return new ChangePasswordTable();
		}

		/// <summary>
		/// Create as new instance of ChangePasswordRow.
		/// </summary>
		/// <param name="builder">Builder for data row.</param>
		protected override System.Data.DataRow NewRowFromBuilder(System.Data.DataRowBuilder builder) {
			return new ChangePasswordRow(builder);
		}

		/// <summary>
		/// Count of rows.
		/// </summary>
		public int Count {
			get {
				return base.Rows.Count;
			}
		}

		/// <summary>
		/// Get row.
		/// </summary>
		/// <param name="index">Index of row.</param>
		public ChangePasswordRow this[int index] {
			get {
				return (ChangePasswordRow)(base.Rows[index]);
			}
			set {
				throw new System.NotImplementedException();
			}
		}

		/// <summary>
		/// Add a row.
		/// </summary>
		/// <param name="row" >Row which will be added.</param>
		public void AddRow(ChangePasswordRow row) {
			base.Rows.Add(row);
		}

		/// <summary>
		/// Remove a row.
		/// </summary>
		/// <param name="row" >Row which will be removed.</param>
		public void RemoveRow(ChangePasswordRow row) {
			base.Rows.Remove(row);
		}

		/// <summary>
		/// Add a new row with default values.
		/// </summary>
		public ChangePasswordRow AddNewRow() {
			var row = base.NewRow() as ChangePasswordRow;

			System.Diagnostics.Debug.Assert(row != null);

			base.Rows.Add(row);

			return row;
		}

		/// <summary>
		/// Type of data row.
		/// </summary>
		protected override System.Type GetRowType() {
			return typeof(ChangePasswordRow);
		}

		#region Members of System.Collections.Generic.IEnumerable<ChangePasswordRow>.

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public int IndexOf(ChangePasswordRow item) {
			return base.Rows.IndexOf(item);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index" ></param>
		/// <param name="item" ></param>
		public void Insert(int index, ChangePasswordRow item) {
			base.Rows.InsertAt(item, index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index"></param>
		public void RemoveAt(int index) {
			base.Rows.RemoveAt(index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="item" ></param>
		public void Add(ChangePasswordRow item) {
			base.Rows.Add(item);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		bool System.Collections.Generic.ICollection<ChangePasswordRow>.Contains(ChangePasswordRow item) {
			throw new System.NotImplementedException();
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="keys" ></param>
		/// <returns></returns>
		public bool ContainsKey(params object[] keys) {
			System.Diagnostics.Debug.Assert(keys != null);
			System.Diagnostics.Debug.Assert(keys.Length != 0);

			return base.Rows.Contains(keys);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="array" ></param>
		/// <param name="arrayIndex" ></param>
		public void CopyTo(ChangePasswordRow[] array, int arrayIndex) {
			base.Rows.CopyTo(array, arrayIndex);
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsReadOnly {
			get {
				return false;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		public bool Remove(ChangePasswordRow item) {
			base.Rows.Remove(item);
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		public IEnumerator<ChangePasswordRow> GetEnumerator() {
			var iter = base.Rows.GetEnumerator();
			while (iter.MoveNext()) {
				yield return iter.Current as ChangePasswordRow;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
			return base.Rows.GetEnumerator();
		}

		#endregion

		/// <summary>
		/// Initialize data table.
		/// </summary>
		public ChangePasswordTable() {
			this.TableName = "ChangePasswordTable";
			this.BeginInit();
			var column0 = new System.Data.DataColumn("userId", typeof(string), null, System.Data.MappingType.Attribute);
			column0.Unique = true;
			base.Columns.Add(column0);
			var column1 = new System.Data.DataColumn("password", typeof(string), null, System.Data.MappingType.Attribute);
			column1.DefaultValue = "";
			base.Columns.Add(column1);
			var column2 = new System.Data.DataColumn("newPassword", typeof(string), null, System.Data.MappingType.Attribute);
			column2.DefaultValue = "";
			base.Columns.Add(column2);
			this.EndInit();
		}
	} // end of ChangePasswordTable.

	/// <summary>
	/// ChangePasswordRow.
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class ChangePasswordRow : System.Data.DataRow {
		/// <summary>
		/// Initialize data row.
		/// </summary>
		public ChangePasswordRow(System.Data.DataRowBuilder builder)
			: base(builder) {
		}

		/// <summary>
		/// 
		/// </summary>
		public string UserId {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnUserId];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of ChangePasswordTable[\"UserId\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[ChangePasswordTable.ColumnUserId];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetUserIdNull() {
			var col = base.Table.Columns[ChangePasswordTable.ColumnUserId];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsUserIdNull {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnUserId];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 原密码
		/// </summary>
		public string Password {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnPassword];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of ChangePasswordTable[\"password\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[ChangePasswordTable.ColumnPassword];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetPasswordNull() {
			var col = base.Table.Columns[ChangePasswordTable.ColumnPassword];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsPasswordNull {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnPassword];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 新密码
		/// </summary>
		public string NewPassword {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnNewPassword];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of ChangePasswordTable[\"newPassword\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[ChangePasswordTable.ColumnNewPassword];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetNewPasswordNull() {
			var col = base.Table.Columns[ChangePasswordTable.ColumnNewPassword];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsNewPasswordNull {
			get {
				var col = base.Table.Columns[ChangePasswordTable.ColumnNewPassword];

				return base.IsNull(col);
			}
		}

	} // end of ChangePasswordRow.
}
